package snsdbook.engine;

import static java.nio.file.FileVisitResult.CONTINUE;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;

public class FileAccumulatorVisitor extends SimpleFileVisitor<Path> {

  private ArrayList<File> list_;
  
  public FileAccumulatorVisitor() {
    list_ = new ArrayList<File>();
  }
  
  public File[] list() {
    File[] ret = new File[list_.size()];
    list_.toArray(ret);
    return ret;
  }

  // Accumulate absolute path to array list.
  @Override
  public FileVisitResult visitFile(Path file,
                                   BasicFileAttributes attr) {
    list_.add(file.toFile());
    return CONTINUE;
  }

  // Print each directory visited.
  @Override
  public FileVisitResult postVisitDirectory(Path dir,
                                            IOException exc) {
    return CONTINUE;
  }
}

